using UnityEngine;
using System.Collections;

public class EnemyAlertState : State<EnemyControl> 
{
    #region Singleton

    private static EnemyAlertState instance = new EnemyAlertState();
    public static EnemyAlertState Instance { get { return instance; } }
    private EnemyAlertState() {}

    #endregion

    #region State

    public override void OnEnterState(EnemyControl behaviour)
    {
        behaviour.waitTimeEndState = Time.timeSinceLevelLoad + behaviour.waitTimeAlert;
        behaviour.waitTimeEndAction = Time.timeSinceLevelLoad + behaviour.waitTimeAlertLookDirection;
    }

    public override void OnUpdateState(EnemyControl behaviour)
    {
        if (behaviour.IsTargetInAttackRange())
            behaviour.State = EnemyAttackState.Instance;
        else if (behaviour.IsTargetInViewRange())
            behaviour.State = EnemyHuntState.Instance;
        else if (behaviour.waitTimeEndState <= Time.timeSinceLevelLoad)
            behaviour.State = EnemyPatrolState.Instance;
        else if (behaviour.waitTimeEndAction <= Time.timeSinceLevelLoad)
        {
            behaviour.waitTimeEndAction = Time.timeSinceLevelLoad + behaviour.waitTimeAlertLookDirection;
            behaviour.TurnAround();
        }
    }

    public override void OnFixedUpdateState(EnemyControl behaviour)
    {
    }

    public override void OnExitState(EnemyControl behaviour)
    {
        
    }

    public override void OnCollisionState(EnemyControl behaviour, Collision other)
    {
    }

    public override void OnTriggerState(EnemyControl behaviour, Collider other)
    {
    }

    #endregion
}
